//1、导入koa
const Koa = require('koa');
//2、实例化koa对象
const app = new Koa();
//3、编写中间件
app.use((ctx) => {
    //ctx.body = 'hello world koa';
    console.log(ctx)
    if(ctx.request.url == '/'){
        ctx.response.body = '这是首页';
    }else if(ctx.request.url == '/users'){
        if(ctx.request.method == 'GET'){
            ctx.response.body = '这是用户页';
        }else if(ctx.request.method == 'POST'){
            ctx.response.body = '创建用户';
        }else{
            ctx.status = 405;
        }
    }else{
        ctx.status = 404;
    }
})
//4、启动服务，监听3000端口
app.listen(3000, () => {
    console.log('koa服务器启动成功~');
})